<template>
  <div class="complete-list">
    <p class="complete-title">
      共有
      <span class="people-count">{{size}}</span> 人完成本课
    </p>
    <div class="photo">
      <div class="photo-left">
        <template v-for="(item, index) in list">
          <div :key="index" v-if="index < 10">
            <span class="img cursor">
              <img class="i" :src="item.head_img_url ? item.head_img_url : require('../../../assets/images/student.png') " />
            </span>
            <span>{{item.name}}</span>
          </div>
        </template>
      </div>
      <div class="photo-right">
        <span class="cursor" @click="getFinishedList">更多</span>
      </div>
    </div>

    <el-dialog title="课程学习完成情况" :visible.sync="dialogTableVisible">
      <div class="table-title">{{info.lessonName}}</div>
      <div class="table-desc">章：{{info.fatherChapterName}}</div>
      <div class="table-desc">单元：{{info.chapterName}}</div>
      <div class="table-desc last-child">
        共有
        <span style="color:#F86F33">{{info.finishedSize}}</span>
        人完成本课
      </div>
      <InsTable :table-head="tableHead" :table-data="tableData" :index="true">
        <!-- 自定义列 点赞 -->
          <el-table-column slot="like_num" slot-scope="headScope" :width="140" align="center" :label="headScope.head.label">
            <template slot-scope="scope">
             <!-- <img style="width: 18px;height: 18px;" src="../../../assets/images/icon_dz2@2x.png" alt=""> -->
             <!-- <img style="width: 18px;height: 18px;" class="dz" src="../../../assets/images/icon_dz@2x.png" alt=""> -->
             {{scope.row.like_num}}
            </template>
          </el-table-column>
      </InsTable>
    </el-dialog>
  </div>
</template>
<script>
import { finishedList } from '@/api/student/lesson/study'
import { taskFinishedList } from '@/api/student/lesson/task'

import InsTable from '@/components/InsTable'

export default {
  name: 'CompleteList',
  components: {
    InsTable
  },
  props: {
    type: { // 1-学习 2-任务
      type: Number,
      default: 1
    },
    list: {
      type: Array,
      default: () => []
    },
    size: {
      type: Number,
      default: 0
    },
    resourceLessonChapterId: { // id
      type: String,
      default: ''
    }
  },
  data () {
    return {
      dialogTableVisible: false,
      info: {},
      tableHead: [
        {
          label: '姓名',
          prop: 'name'
        },
        // {
        //   label: '完成率',
        //   prop: 'finishedRate'
        // },
        {
          label: '完成时间',
          prop: 'end_time'
        },
        {
          label: '耗时',
          prop: 'duration',
          width: '80'
        },
        {
          label: '点赞数',
          prop: 'like_num',
          width: '80',
          isSlot: true
        }
      ],
      tableData: []
    }
  },
  methods: {
    async getFinishedList () {
      let res
      if (this.type === 1) {
        res = await finishedList({
          resourceLessonChapterId: this.resourceLessonChapterId,
          pageNum: 1
        })
      } else if (this.type === 2) {
        res = await taskFinishedList({
          id: this.resourceLessonChapterId,
          pageNum: 1
        })
      }
      this.dialogTableVisible = true
      this.info = res.data
      this.tableData = res.data.finishedList
    }
  }
}
</script>

<style lang="scss" scoped>
.complete-list {
  border-top: 1px solid rgba(245, 245, 246, 1);
  border-bottom: 1px dashed #e5e5e5;
  font-size: 14px;
  padding-bottom: 24px;
  padding-top: 20px;
  .complete-title {
    margin-bottom: 12px;
    .people-count {
      color: #f86f33;
      padding: 0 3px;
    }
  }
  .photo {
    margin: 10px 0;
    display: flex;
    justify-content: space-between;
    .photo-left {
      display: flex;
      width: 90%;
      // justify-content: space-around;
      overflow: hidden;
      .img {
        flex-shrink: 1;
        overflow: hidden;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: block;
        padding-bottom: 10px;
        margin-right: 20px;
        img {
          width: 40px;
          height: 40px;
          border-radius: 50%;
        }
        .i {
          width: 100%;
          height: 100%;
        }
      }
    }
    .photo-right {
      display: flex;
      align-items: center;
      color: #009cf6;
      padding-right: 5px;
    }
  }
  .table-title {
    font-size: 20px;
    font-family: PingFang SC;
    font-weight: bold;
    color: rgba(16, 29, 55, 1);
    line-height: 43px;
  }
  .table-desc {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    color: rgba(16, 29, 55, 1);
    line-height: 20px;
    &.last-child {
      margin-top: 20px;
      margin-bottom: 10px;
    }
  }
}
</style>
